﻿@model Sheng.WeixinConstruction.Management.Shell.Models.BaseViewModel

@{
    ViewBag.MainMenu = "Settings";
    ViewBag.LeftMenu = "Base";

    ViewBag.Title = "基本设置";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@*@Scripts.Render("~/Scripts/jquery.form.js")*@

<script type="text/javascript">

    var _validator;

    $(document).ready(function () {
        if (_online == false)
            return;

        $("#selectTheme").find("option[value='@Model.ThemeStyleSettings.Theme']").attr("selected", true);

        $("[keyenter]").keypress(function (e) {
            if (e.keyCode == 13) {
                save();
            }
        });

        _validator = $("#form").validate({
            onfocusout: false,
            onkeyup: false,
            showErrors: showValidationErrors,
            rules: {
                "txtName": "required",
                "txtInitialMemberPoint": {
                    required: true,
                    number: true,
                    digits: true,
                    range: [0, 10000]
                },
                "txtSignInPoint": {
                    required: true,
                    number: true,
                    digits: true,
                    range: [1, 100]
                }
            },
            messages: {
                "txtName": "请输入公众号名称；",
                "txtInitialMemberPoint": {
                    required: "请输入会员初始积分；",
                    number: "会员初始积分请输入有效整数字；",
                    digits: "会员初始积分请输入有效整数字；",
                    range: "会员初始积分请介于 0 到 10000 之间；"
                },
                "txtSignInPoint": {
                    required: "请输入每日签到积分；",
                    number: "每日签到积分请输入有效整数字；",
                    digits: "每日签到积分请输入有效整数字；",
                    range: "每日签到积分请介于 1 到 100 之间；"
                }
            }
        });


    });

    function save() {
        if (_validator.form() == false) {
            return;
        }

        var loadLayerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        var args = new Object();
        args.Settings = new Object();
        args.Settings.GuideSubscribeUrl = $("#txtGuideSubscribeUrl").val();
        args.Settings.DefaultMemberCardLevel = $("#selectDefaultMemberCardLevel").val();
        args.Settings.InitialMemberPoint = $("#txtInitialMemberPoint").val();
        args.Settings.SignInPoint = $("#txtSignInPoint").val();
        args.Settings.PointCommodityGetWay = $("#txtPointCommodityGetWay").val();
        args.ThemeStyleSettings = new Object();
        args.ThemeStyleSettings.Theme = $("#selectTheme").val();

        var url = "/Api/Settings/SaveSettings";

        $.ajax({
            url: url,
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR) {
                layer.close(loadLayerIndex);
                if (data.Success) {
                    layerAlert("保存成功，您的设置将在几分钟之内生效。");
                } else {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(loadLayerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

</script>

<style type="text/css">
    .divBaseSettingsTitle {
        margin-top: 25px;
        margin-left: 10px;
        margin-right: 10px;
    }

    .divBaseSettings {
        margin-top: 20px;
        margin-left: 10px;
        margin-right: 10px;
    }
</style>

<div id="divContentTips">
    配置您日常运营的基础信息。
    @*<a href="#">查看详细&gt;</a>*@
</div>

<div>
    <form id="form">
        <div class="divBaseSettingsTitle font_black_22">
            基本信息
        </div>

        <div class="divDotLine" style="margin-top:10px; width:400px;"></div>

        <div class="divBaseSettings">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                @*<tr>
                        <td width="200" height="50" valign="top">公众号名称：</td>
                        <td valign="top">
                        <input name="txtName" type="text" class="input_18" style="width:400px;" id="txtName" maxlength="25" value="@Model.Domain.Name" keyenter />
                        </td>
                    </tr>*@
                <tr>
                    <td width="200" height="50">引导关注页面：</td>
                    <td>
                        <input name="txtGuideSubscribeUrl" type="text" class="input_18" style="width:96%;" id="txtGuideSubscribeUrl" maxlength="500" value="@Model.Settings.GuideSubscribeUrl" keyenter />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <div class="font_gray_13" style="width:96%;margin-bottom:10px;">
                            当访问需要关注才能浏览的页面时，如果访问者没有关注公众号，将跳转到此地址。
                        </div>
                    </td>
                </tr>
            </table>
        </div>

        <div class="divBaseSettingsTitle font_black_22">
            微官网
        </div>

        <div class="divDotLine" style="margin-top:10px; width:400px;"></div>

        <div class="divBaseSettings">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="200" height="50">主题：</td>
                    <td>
                        <select id="selectTheme" name="selectTheme" class="input_16" style="width:200px;" keyenter=keyenter>
                            <option value="red">红</option>
                            <option value="blue">蓝</option>
                            <option value="yellow">黄</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <div class="font_gray_13" style="width:96%;margin-bottom:10px;">
                            各个页面的主题颜色。
                        </div>
                    </td>
                </tr>
            </table>
        </div>

        <div class="divBaseSettingsTitle font_black_22">
            微会员
        </div>

        <div class="divDotLine" style="margin-top:10px; width:400px;"></div>

        <div class="divBaseSettings">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="200" height="50">默认会员卡：</td>
                    <td>
                        <select id="selectDefaultMemberCardLevel" name="selectDefaultMemberCardLevel" class="input_16" style="width:200px;" keyenter=keyenter>
                            <option></option>
                            @foreach (var item in Model.MemberCardLevelList)
                            {
                                <option value="@item.Id" @if (item.Id == Model.Settings.DefaultMemberCardLevel) { @Html.Raw("selected") }>@item.Name</option>
                            }
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <div class="font_gray_13" style="width:96%;margin-bottom:10px;">
                            请在“会员卡级别”中配置您的不同会员卡种类。
                        </div>
                    </td>
                </tr>
                <tr>
                    <td width="200" height="50">初始积分：</td>
                    <td>
                        <input name="txtInitialMemberPoint" type="text" class="input_18" style="width:200px;" id="txtInitialMemberPoint" value="@Model.Settings.InitialMemberPoint" keyenter />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <div class="font_gray_13" style="width:96%;margin-bottom:10px;">
                            修改会员初始积分仅对修改后的新关注者起作用。
                        </div>
                    </td>
                </tr>
                <tr>
                    <td height="50">每日签到积分：</td>
                    <td>
                        <input name="txtSignInPoint" type="text" class="input_18" style="width:200px;" id="txtSignInPoint" value="@Model.Settings.SignInPoint" keyenter />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <div class="font_gray_13" style="width:96%;margin-bottom:10px;">
                            建议您不要使用过大数值的积分系统，以免用户体验不佳。
                        </div>
                    </td>
                </tr>
            </table>
        </div>




        <div class="divBaseSettingsTitle font_black_22">
            积分商城
        </div>

        <div class="divDotLine" style="margin-top:10px; width:400px;"></div>

        <div class="divBaseSettings">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="200">积分商品领取方法：</td>
                    <td>
                        <textarea name="txtPointCommodityGetWay" rows="4" class="input_18" id="txtPointCommodityGetWay" style="width:96%;" maxlength="250">@Model.Settings.PointCommodityGetWay</textarea>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <div class="font_gray_13" style="width:96%;margin-bottom:10px;margin-top:10px;">
                            会员兑换积分商品后，领取方法将显示在订单页面的下方。
                        </div>
                    </td>
                </tr>
            </table>
        </div>

        <div style=" margin-top:15px;">
            <input name="btnSave" type="button" class="btn_blue" id="btnSave" value="保存" onclick="save()" />
        </div>
    </form>
</div>
@Helpers.FileUpload()